<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>

<head>
    <!-- 页面meta -->
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>机构管理</title>
    <!-- Tell the browser to be responsive to screen width -->
    <meta content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no" name="viewport">
    <link rel="stylesheet" href="plugins/bootstrap/css/bootstrap.min.css">
    <link rel="stylesheet" href="plugins/adminLTE/css/AdminLTE.css">
    <link rel="stylesheet" href="plugins/adminLTE/css/skins/_all-skins.min.css">
    <link rel="stylesheet" href="css/style.css">
    <script src="plugins/jQuery/jquery-2.2.3.min.js"></script>
    <script src="plugins/bootstrap/js/bootstrap.min.js"></script>

    <link rel="stylesheet" href="plugins/angularjs/toaster.min.css">
    <%--<script type="text/javascript" src="plugins/angularjs/angular.min.js"></script>
    <script type="text/javascript" src="plugins/angularjs/angular-animate.min.js"></script>
    <script type="text/javascript" src="plugins/angularjs/toaster.min.js"></script>

    <!--引入分页插件资源-->
    <link rel="stylesheet" href="plugins/angularjs/pagination.css">
    <script type="text/javascript" src="plugins/angularjs/pagination.js"></script>

    <script type="text/javascript" src="js/base_pagination.js"></script>
    <script type="text/javascript" src="js/service/organService.js"></script>
    <script type="text/javascript" src="js/controller/baseController.js"></script>
    <script type="text/javascript" src="js/controller/organController.js"></script>--%>
    <c:set var="path" value="${pageContext.request.contextPath}"/>
    <script type="text/javascript">
        function query() {
            $.ajax({
                url: "${path}/Organization/selectAll?page=1&pageNum=5&status=14",
                type: "post",
                success: function () {
                    location.reload();
                }
            })
        }

        function save() {
            var departmentName = $("#departmentName").val();
            var id = $("#id option:selected").val();
            console.log(id, departmentName);
            if (departmentName == "" || departmentName == null) {
                alert("请输入部门名称");
                return;
            }
            if (id == "" || id == null) {
                alert("请选择岗位名称");
                return;
            }
            $.ajax({
                url: "${path}/Organization/insert",
                data: "departmentName=" + departmentName + "&id=" + id,
                dataType: "json",
                success: function (status) {
                    if (status == true) {
                        alert("添加成功");
                        query();
                    } else {
                        $("#text").html(status);
                    }
                }
            })
        }

        function update() {
            let departmentName = $("#departmentName2").val();
            var id = $("#ids").val();
            let postId = $("#postId option:selected").val();
            $.ajax({
                url: "${path}/Organization/update",
                data: "id=" + id + "&departmentName=" + departmentName + "&postId=" + postId,
                dataType: "json",
                success: function (status) {
                    if (status == true) {
                        alert("修改成功");
                        query();
                    }
                }
            });
        }

        function selectById(id) {
            $.ajax({
                url: "${path}/Organization/selectById",
                data: "id=" + id,
                dataType: "json",
                success: function (data) {
                    $("#ids").val(id);
                    $("#departmentName2").val(data.departmentName);
                    $("#postId").val(data.higherAuthoritiesId);
                }
            });
        }

        function deletes(id) {
            if (confirm("确定删除吗")) {
                $.ajax({
                    url: "${path}/Organization/delete",
                    data: "id=" + id,
                    dataType: "json",
                    success: function (status) {
                        if (status == true) {
                            alert("删除成功");
                            query();
                        }
                    }
                });
            }
        }
    </script>
</head>
<body class="hold-transition skin-red sidebar-mini" ng-app="shebao" ng-controller="organController"
      ng-init="selectOrganlist()">
<!-- .box-body -->
<toaster-container toaster-options="{'time-out': 1000,'position-class':'toast-center'}"></toaster-container>
<div class="box-header with-border">
    <h3 class="box-title">机构管理</h3>
</div>
<div class="box-body">
    <div class="has-feedback">
        <div style="text-align: center;background: #ffff">
            <table align="center" ng-init="searchEntity.state=0">
            </table>
        </div>
    </div>
</div>
<div class="box-body">
    <!-- 数据表格 -->
    <div class="table-box">

        <!--工具栏-->
        <div class="pull-left">
            <div class="form-group form-inline">
                <div class="btn-group">
                    <button type="button" class="btn btn-default" title="添加" data-toggle="modal"
                            data-target="#editModal" ng-click="addClick()"><i class="fa fa-file-o"></i> 添加
                    </button>
                </div>
            </div>
        </div>
        <!--工具栏/-->
        <!--数据列表-->
        <table id="dataList" class="table table-bordered table-striped table-hover dataTable">
            <thead>
            <tr>
                <th class="sorting">部门id</th>
                <th class="sorting">部门名称</th>
                <th class="sorting">岗位id</th>
                <th class="sorting">操作</th>
            </tr>
            </thead>
            <c:forEach var="o" items="${organizations}">
                <tbody>
                <tr>
                    <td>${o.id}</td>
                    <td>${o.departmentName}</td>
                    <td>${o.higherAuthoritiesId}</td>
                    <td class="text-center"><%--ng-click="findOne(pojo.id)"--%>
                        <button type="button" onclick="selectById(${o.id})" class="btn bg-olive btn-xs"
                                data-toggle="modal" data-target="#editModal2">编辑
                        </button>
                            <%--ng-click="deleteOne(pojo.id)"--%>
                        <button type="button" onclick="deletes(${o.id})" class="btn bg-olive btn-xs">删除
                        </button>
                    </td>
                </tr>
                </tbody>
            </c:forEach>
        </table>
        <!--数据列表/-->
        <!--分页工具条展示-->
        <%--<tm-pagination conf="paginationConf"></tm-pagination>--%>
        <ul class="pager pull-left">
            <li>
                <c:if test="${map.page>1}">
                    <a href="${path}/Organization/selectAll?page=${map.page-1}&pageNum=5&status=14">上一页</a>
                </c:if>

                <c:if test="${map.page==1}">
                    <a href="#" class="btn btn-default disabled">上一页</a>
                </c:if>
            </li>
            第 ${map.page} 页&nbsp;&nbsp;&nbsp;共 ${map.num} 页
            <li>
                <c:if test="${map.page<map.num}">
                    <a href="${path}/Organization/selectAll?page=${map.page+1}&pageNum=5&status=14">下一页</a>
                </c:if>

                <c:if test="${map.page==map.num}">
                    <a href="#" class="btn btn-default disabled">下一页</a>
                </c:if>
            </li>
        </ul>
        <br/>

        <div class="text-right">
            <c:if test="${map.counts==null}">
                共 ${map.count} 条数据
            </c:if>
        </div>
    </div>
    <!-- 数据表格 /-->
</div>
<!-- /.box-body -->
<!-- 编辑窗口 -->
<div class="modal fade" id="editModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog" style="width:80%;">
        <div class="modal-content">
            <div class="modal-header">
                <button id="bt1" type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
                <h3 id="myModalLabel">信息添加</h3>
            </div>
            <div class="modal-body">
                <table class="table table-bordered table-striped">
                    <tr>
                        <td>
                            部门名称：
                        </td>
                        <%--ng-model="entity.departmentName"--%>
                        <td colspan="2"><input id="departmentName"
                                               class="form-control"
                                               placeholder="部门名称"></td>
                        <td align="right">
                            岗位名称：
                        </td>
                        <td colspan="2">
                            <%--ng-model="entity.higherAuthoritiesId"--%>
                            <select class="form-control" id="id">
                                <option value="">全部</option>
                                <c:forEach items="${post}" var="p">
                                    <option value="${p.id}">${p.postName}</option>
                                </c:forEach>
                            </select>
                        </td>
                    </tr>
                </table>
                <div id="text" style="color: red"></div>
            </div>
            <div class="modal-footer"><%--ng-click="verify()"--%>
                <button class="btn btn-success" onclick="save()">保存</button>
                <button class="btn btn-default" data-dismiss="modal" aria-hidden="true">关闭</button>
            </div>
        </div>
    </div>
</div>
<div class="modal fade" id="editModal2" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog" style="width:80%;">
        <div class="modal-content">
            <div class="modal-header">
                <button id="bt2" type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
                <h3 id="myModalLabel2">信息修改</h3>
            </div>
            <div class="modal-body">
                <table class="table table-bordered table-striped">
                    <tr>
                        <td>
                            部门名称：
                        </td>
                        <input id="ids" type="hidden"/>
                        <%--ng-model="entity.departmentName"--%>
                        <td colspan="2"><input id="departmentName2"
                                               class="form-control"
                                               placeholder="部门名称"></td>
                        <td align="right">
                            岗位名称：
                        </td>
                        <td colspan="2">
                            <%--ng-model="entity.higherAuthoritiesId"--%>
                            <select class="form-control" id="postId">
                                <c:forEach items="${post}" var="p">
                                    <option value="${p.id}">${p.postName}</option>
                                </c:forEach>
                            </select>
                        </td>
                    </tr>
                </table>
                <div id="text2" style="color: red"></div>
            </div>
            <div class="modal-footer"><%--ng-click="verify()"--%>
                <button class="btn btn-success" onclick="update()">保存</button>
                <button class="btn btn-default" data-dismiss="modal" aria-hidden="true">关闭</button>
            </div>
        </div>
    </div>
</div>
</body>
</html>